#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <arpa/inet.h>
#include <algorithm>
#include <vector>

std::vector<int> oports;
int arraynum = 0;
int perc = 1;

boost::mutex io_mutex;

void scan(int port, const char *addr)
{
   char buffer[1024];
   memset(buffer,0,sizeof(buffer));
   boost::mutex::scoped_lock lock(io_mutex);
   struct sockaddr_in address;
   int sock;
   memset((void *) &address, 0, sizeof(struct sockaddr_in));
   address.sin_family = AF_INET;
   address.sin_addr.s_addr = inet_addr(addr);
   address.sin_port = htons(port);
   sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
   bind(sock, (const struct sockaddr *) &address, sizeof(address));
   if (connect(sock,(const struct sockaddr *)&address,sizeof(address)) == 0)
   {
      oports.push_back(port);
      sort(oports.begin(),oports.end());
      arraynum++;
   }
   close(sock);
   perc++;
}
